<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%>
<div class="panel border-back" id="write_goods_info_div">
	<div class="panel-body">
		<div class="line-big">
			<div class="xl10 text-left">
				<button class="button border-blue" id="select_all_order_id">
					<span class="icon-star"></span> 全选
				</button>
				<button class="button border-blue" id="reverse_select_all_order_id">
					<span class="icon-star-half-empty"></span> 反选
				</button>
				<c:choose>
					<c:when test="${s=='待付款' }"></c:when>
					<c:when test="${s=='待发货' }">
						<!-- <button class=" button bg-red" id="batch_send_order">
							<span class="icon-send"></span> 批量确认派送
						</button> -->
						<!-- <button class=" button bg-red" id="batch_send_and_print_order_button">
							<span class="icon-send"></span> 批量确认派送&nbsp;并&nbsp;<span class="icon-print"></span> 打印订单
						</button> -->
					</c:when>
					<c:when test="${s=='待收货' }">
						<button class=" button bg-red" id="batch_receive_order">
							<span class="icon-check"></span> 确认送达
						</button>
						<!-- <button class=" button bg-red" id="batch_print_order">
							<span class="icon-send"></span> 批量打印订单
						</button> -->
					</c:when>
					<c:when test="${s=='交易完成' }">
						<!-- <button class=" button bg-red" id="batch_print_order">
							<span class="icon-send"></span> 批量打印订单
						</button> -->
					</c:when>
					<c:when test="${s=='交易取消' }"></c:when>
				</c:choose>
			</div>
			<div class="xl2 text-right">
				<div class="field field-icon-right" title="查找订单">
					<span class="icon icon-search" id="search_order_button"></span>
					<input type="text" class="input radius-rounded" id="keyword_of_order_input" value="${param.k }" placeholder="订单号" />
				</div>

			</div>
		</div>

	</div>
	<div class="panel-foot bg-yellow-light border-back">
		<div class="line-big">
			<div class="xl4 text-center border-small border-right border-blue">商品信息</div>
			<div class="xl1 text-center border-small border-right border-blue">单价(元)</div>
			<div class="xl1 text-center border-small border-right border-blue">数量</div>
			<div class="xl2 text-center border-small border-right border-blue">付款(元)</div>
			<div class="xl2 text-center border-small border-right border-blue">退换货状态</div>
			<div class="xl2 text-center">操作</div>
		</div>
	</div>
	<ul class="list-group list-striped">
		<c:forEach items="${complexOrderReturnList }" var="co" varStatus="coStat">
			<li id="li_${co.orderReturn.orderReturnId }">
				<div class="line-big">
					<div class="xl6 text-left">
						<input class="order_id_check_box" type="checkbox" data-id="${co.orderReturn.orderReturnId }" data-li="#li_${co.orderReturn.orderReturnId }">
						<strong class="margin-left"><span class="icon-clock-o"></span> <fmt:formatDate value="${co.orderReturn.orderReturnBeginTime }" pattern="yyyy-MM-dd HH:mm" />(退换货开始时间) <span
							class="icon-file-text-o margin-left"></span> 退换货编号：${co.order.orderId }</strong>
					</div>
					<div class="xl6 text-left">
						<strong><span class="glyphicon glyphicon-user"></span> 收货人：${co.order.orderBuyerName} ${co.order.orderBuyerPhone} ， <span class="glyphicon glyphicon-map-marker"></span> 派送至：${co.order.orderBuyerAddress}</strong>
					</div>
				</div>
			</li>
			<li id="li_${co.orderReturn.orderReturnId }_2">
				<div class="line-big">
					<div class="xl6 text-center">
						<c:forEach items="${co.goodsHistoryItemList}" var="goodsHistoryItem" varStatus="giStat">
							<div class="line-big">
								<div class="xl2 text-center">
									<img class="center-block img-responsive" style="max-height: 60px; max-width: 60px;" src="${goodsHistoryItem.goodsHistory.goodsMainPic }" />
								</div>
								<div class="xl6 text-center">
									<h5 class="text-left">
										<strong> <a href="${basePath }snapshot/${goodsHistoryItem.goodsHistory.historyId }">${goodsHistoryItem.goodsHistory.goodsName }</a>
										</strong>
									</h5>
									<h6 class="text-left G-MarginTop10">${goodsHistoryItem.goodsHistory.goodsTips}</h6>
									<h6 class="text-left G-MarginTop10">
										<button class="see_snapshot_button dialogs button button-little bg-default" data-li="#li_${co.order.orderId }" data-toggle="click" data-target="#see_goods_history_dialog" data-mask="1" data-width="960px"
											data-url="${basePath }shop/show_goods_snapshot?commonStr=${goodsHistoryItem.goodsHistory.historyId }">
											<span class="icon-eye"></span> 交易快照
										</button>
									</h6>
								</div>
								<div class="xl2 text-center">
									<fmt:formatNumber value="${goodsHistoryItem.goodsHistory.goodsPrice }" type="currency" pattern="#,##0.##" />
								</div>
								<div class="xl2 text-center">${goodsHistoryItem.number }</div>
							</div>
							<c:if test="${fn:length(co.goodsHistoryItemList)!=giStat.count}">
								<hr class="">
							</c:if>
						</c:forEach>
					</div>
					<div class="xl2 text-center">
						<strong> <fmt:formatNumber value="${co.order.orderTotalPrice }" type="currency" pattern="#,##0.##" />
						</strong>
						<h6 class="text-left G-MarginTop10">订单号:${co.order.orderId}(${co.order.operationMode })</h6>
					</div>
					<div class="xl2 text-center">
						<c:choose>
							<c:when test="${co.orderReturn.orderReturnStatus=='申请审核中' }">
								<span class="badge bg-blue" title='退换货原因：${co.orderReturn.orderReturnReason }'>${co.orderReturn.orderReturnType}</span>
								申请审核中
								<div class="border border-blue G-MarginTop10 text-left">
									<span style="font-size: 12px;">退换货原因：${co.orderReturn.orderReturnReason }</span>
								</div>
							</c:when>
							<c:when test="${co.orderReturn.orderReturnStatus=='买家退换货中' }">
								<span class="badge bg-blue" title='退换货原因：${co.orderReturn.orderReturnReason }'>${co.orderReturn.orderReturnType}</span>
								买家退换货中
								<c:if test="${co.orderReturn.orderBuyerExpressCompany!=null&&co.orderReturn.orderBuyerExpressCompany!='' }">
									<div class="border border-blue G-MarginTop10 text-center">
										<span style="font-size: 12px;">快递公司：${co.orderReturn.orderBuyerExpressCompany }</span><br> <span style="font-size: 12px;">快递单号：${co.orderReturn.orderBuyerExpressNumber }</span>
										<a title="点击查看快递信息" target="_blank" class="bg-blue radius-circle text-little" href="http://www.kuaidi100.com/chaxun?com=${co.orderReturn.orderBuyerExpressCompany }&nu=${co.orderReturn.orderBuyerExpressNumber }">
											&nbsp;<span class="icon-eye text-little text-white"></span>&nbsp;
										</a>
									</div>
								</c:if>
							</c:when>
							<c:when test="${co.orderReturn.orderReturnStatus=='卖家处理中' }">
								<span class="badge bg-blue" title='退换货原因：${co.orderReturn.orderReturnReason }'>${co.orderReturn.orderReturnType}</span>
								卖家处理中
								<c:if test="${co.orderReturn.orderReturnType=='换货'&&co.orderReturn.orderSellerExpressCompany!=null&&co.orderReturn.orderSellerExpressCompany!='' }">
									<div class="border border-blue G-MarginTop10 text-center">
										<span style="font-size: 12px;">快递公司：${co.orderReturn.orderSellerExpressCompany }</span><br> <span style="font-size: 12px;">快递单号：${co.orderReturn.orderSellerExpressNumber }</span>
										<a title="点击查看快递信息" target="_blank" class="bg-blue radius-circle text-little"
											href="http://www.kuaidi100.com/chaxun?com=${co.orderReturn.orderSellerExpressCompany }&nu=${co.orderReturn.orderSellerExpressNumber }">
											&nbsp;<span class="icon-eye text-little text-white"></span>&nbsp;
										</a>
									</div>
								</c:if>
							</c:when>
							<c:when test="${co.orderReturn.orderReturnStatus=='已完成' }">
								<span class="badge bg-blue" title='退换货原因：${co.orderReturn.orderReturnReason }'>${co.orderReturn.orderReturnType}</span>
								已完成
							</c:when>
							<c:when test="${co.orderReturn.orderReturnStatus=='申请未通过' }">
								<span class="badge bg-blue" title='退换货原因：${co.orderReturn.orderReturnReason }'>${co.orderReturn.orderReturnType}</span>
								申请未通过</c:when>
						</c:choose>
					</div>
					<div class="xl2 text-center">
						<c:choose>
							<c:when test="${co.orderReturn.orderReturnStatus=='申请审核中' }">
								<button class="agree_apply_button button bg-blue" data-id="${co.orderReturn.orderReturnId }" data-li="#li_${co.orderReturn.orderReturnId }">
									<span class="icon-check"></span> 同意申请
								</button>
								<button class="refuse_apply_button button bg-red" data-id="${co.orderReturn.orderReturnId }" data-li="#li_${co.orderReturn.orderReturnId }">
									<span class="icon-times"></span> 拒绝申请
								</button>
								<br />
								<%-- <button class="send_and_print_order_button button bg-red margin-top" data-id="${co.order.orderId }" data-li="#li_${co.order.orderId }">
									<span class="icon-send"></span> 确认派送&nbsp;并&nbsp;<span class="icon-print"></span> 打印订单
								</button> --%>
							</c:when>
							<c:when test="${co.orderReturn.orderReturnStatus=='买家退换货中' }">
								<c:if test="${co.orderReturn.orderBuyerExpressCompany!=null&&co.orderReturn.orderBuyerExpressCompany!='' }">
									<button class="confirm_receive_buyer_express_button button bg-blue" data-id="${co.orderReturn.orderReturnId }" data-li="#li_${co.orderReturn.orderReturnId }">
										<span class="icon-check"></span> 确认收货
									</button>
								</c:if>
							</c:when>
							<c:when test="${co.orderReturn.orderReturnStatus=='卖家处理中' }">
								<c:if test="${co.orderReturn.orderReturnType=='退货' }">
									<button class="confirm_send_buyer_money_button button bg-red" data-id="${co.orderReturn.orderReturnId }" data-li="#li_${co.orderReturn.orderReturnId }">
										<span class="icon-check"></span> 已退款
									</button>
								</c:if>
								<c:if test="${co.orderReturn.orderReturnType=='换货'&&(co.orderReturn.orderSellerExpressCompany==null||co.orderReturn.orderSellerExpressCompany=='') }">
									<button class="send_out_order_return_button button bg-blue" data-id="${co.orderReturn.orderReturnId }" data-li="#li_${co.orderReturn.orderReturnId }">
										<span class="icon-send"></span> 派送订单
									</button>
								</c:if>
							</c:when>
							<c:when test="${co.order.orderStatus=='交易完成' }">
								<%-- <button class="print_order_button button bg-blue margin-top" data-id="${co.order.orderId }" data-li="#li_${co.order.orderId }">
									<span class="icon-print"></span> 打印订单
								</button> --%>
							</c:when>
							<c:when test="${co.order.orderStatus=='交易取消' }"></c:when>
						</c:choose>
					</div>
				</div>
			</li>
		</c:forEach>
	</ul>
	<div class="panel-foot bg-white border-back" id="goods_list_pages" data-url="pages_button" data-index="${page.currentIndex}" data-pages="${page.totalPages}"
		data-href="shop/show_return_order_list?s=${param.s }&k=${param.k }&i="></div>
</div>

<div id="see_comment_dialog"></div>

<div id="see_goods_history_dialog"></div>

<a id="a_link_for_data_href" target="_blank" href="">
	<span id="a_link_span_for_data_href"></span>
</a>
<script type="text/javascript" src="${basePath }js/pintuer.js"></script>
<script type="text/javascript">
	$(function()
	{

		//同意申请
		$(".agree_apply_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认同意退换货申请吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("admin/m_agree_apply_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});

		//拒绝申请
		$(".refuse_apply_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认拒绝退换货申请吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("admin/m_refuse_apply_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});

		//确认收到买家的包裹
		$(".confirm_receive_buyer_express_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认收到此买家的包裹了吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("admin/m_confirm_receive_buyer_express_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});

		//确认已退款给买家
		$(".confirm_send_buyer_money_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认已退款给此买家了吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("admin/m_confirm_send_buyer_money_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});

		//卖家换货填写快递信息
		$(".send_out_order_return_button").each(function()
		{
			var button_obj = $(this);
			button_obj.click(function()
			{
				$("#admin_div").html("");
				$("#admin_div").load("shop/ajax/order_return/add_express_info.jsp",
				{
					id : button_obj.attr("data-id"),
					temp : new Date()
				}, function()
				{

				});
			});
		});

		$("#select_all_order_id").click(function()
		{
			$(".order_id_check_box").attr("checked", true);
		});
		$("#reverse_select_all_order_id").click(function()
		{
			$(".order_id_check_box").each(function()
			{
				$(this).attr("checked", !this.checked);
			});
		});
		$("#batch_send_order").click(function()
		{
			var ids = "";
			var num = 0;
			$("input.order_id_check_box:checked").each(function()
			{
				ids += $(this).attr("data-id") + ",";
				num++;
			});
			if (ids.length <= 0)
			{
				alert("请先勾选需要操作的订单");
				return false;
			}
			ids = ids.substring(0, ids.length - 1);

			if (confirm("确认批量派送这 " + num + " 个订单吗?") == false)
			{
				return false;
			}

			$("#batch_send_order").attr("disabled", "disabled");
			$.post("shop/sp_send_order_do",
			{
				"commonStr" : ids
			}, function(json)
			{
				if (json.success == false)
				{
					alert(json.info);
					$("#batch_send_order").removeAttr("disabled");
				}
				else
				{
					$("#batch_send_order").removeAttr("disabled");
					$("input.order_id_check_box:checked").each(function()
					{
						$($(this).attr("data-li")).remove();
						$($(this).attr("data-li") + "_2").remove();
					});
				}
			},
			//返回类型
			"json");
		});
		$("#batch_send_and_print_order_button").click(function()
		{
			var ids = "";
			var num = 0;
			$("input.order_id_check_box:checked").each(function()
			{
				ids += $(this).attr("data-id") + ",";
				num++;
			});
			if (ids.length <= 0)
			{
				alert("请先勾选需要操作的订单");
				return false;
			}
			ids = ids.substring(0, ids.length - 1);

			if (confirm("确认批量派送这 " + num + " 个订单并打印吗?") == false)
			{
				return false;
			}

			$("#batch_send_order").attr("disabled", "disabled");
			$.post("shop/sp_send_order_do",
			{
				"commonStr" : ids
			}, function(json)
			{
				if (json.success == false)
				{
					alert(json.info);
					$("#batch_send_order").removeAttr("disabled");
				}
				else
				{
					$("#batch_send_order").removeAttr("disabled");
					$("#a_link_for_data_href").attr("href", "shop/shop_print_order?commonStr=" + ids);
					$("#a_link_span_for_data_href").click();
					$("input.order_id_check_box:checked").each(function()
					{
						$($(this).attr("data-li")).remove();
						$($(this).attr("data-li") + "_2").remove();
					});
				}
			},
			//返回类型
			"json");
		});
		$("#batch_print_order").click(function()
		{
			var ids = "";
			var num = 0;
			$("input.order_id_check_box:checked").each(function()
			{
				ids += $(this).attr("data-id") + ",";
				num++;
			});
			if (ids.length <= 0)
			{
				alert("请先勾选需要操作的订单");
				return false;
			}
			ids = ids.substring(0, ids.length - 1);

			if (confirm("确认批量打印这 " + num + " 个订单吗?") == false)
			{
				return false;
			}

			$("#a_link_for_data_href").attr("href", "shop/shop_print_order?commonStr=" + ids);
			$("#a_link_span_for_data_href").click();
		});
		$("#batch_receive_order").click(function()
		{
			var ids = "";
			var num = 0;
			$("input.order_id_check_box:checked").each(function()
			{
				ids += $(this).attr("data-id") + ",";
				num++;
			});
			if (ids.length <= 0)
			{
				alert("请先勾选需要操作的订单");
				return false;
			}
			ids = ids.substring(0, ids.length - 1);

			if (confirm("确认这 " + num + " 个订单已经送达了吗?") == false)
			{
				return false;
			}

			$("#batch_receive_order").attr("disabled", "disabled");
			$.post("shop/sp_receive_order_do",
			{
				"commonStr" : ids
			}, function(json)
			{
				if (json.success == false)
				{
					alert(json.info);
					$("#batch_receive_order").removeAttr("disabled");
				}
				else
				{
					$("#batch_receive_order").removeAttr("disabled");
					$("input.order_id_check_box:checked").each(function()
					{
						$($(this).attr("data-li")).remove();
						$($(this).attr("data-li") + "_2").remove();
					});
				}
			},
			//返回类型
			"json");
		});
		$(".send_and_print_order_button").each(function()
		{
			$(this).click(function()
			{
				if (confirm("确认派送此订单并打印订单吗?") == false)
				{
					return false;
				}
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("shop/sp_send_order_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$("#a_link_for_data_href").attr("href", "shop/shop_print_order?commonStr=" + ids);
						$("#a_link_span_for_data_href").click();
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});
		$(".print_order_button").each(function()
		{
			$(this).click(function()
			{
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				$("#a_link_for_data_href").attr("href", "shop/shop_print_order?commonStr=" + ids);
				$("#a_link_span_for_data_href").click();
			});
		});
		$(".receive_order_button").each(function()
		{
			$(this).click(function()
			{
				var ids = "";
				ids = $(this).attr("data-id");
				var obj = $(this);

				obj.attr("disabled", "disabled");
				$.post("shop/sp_receive_order_do",
				{
					"commonStr" : ids
				}, function(json)
				{
					if (json.success == false)
					{
						alert(json.info);
						obj.removeAttr("disabled");
					}
					else
					{
						obj.removeAttr("disabled");
						$(obj.attr("data-li")).remove();
						$(obj.attr("data-li") + "_2").remove();
					}
				},
				//返回类型
				"json");
			});
		});
		$("#goods_list_pages").load($("#goods_list_pages").attr("data-url"),
		{
			"page.currentIndex" : $("#goods_list_pages").attr("data-index"),
			"page.totalPages" : $("#goods_list_pages").attr("data-pages"),
			"page.href" : $("#goods_list_pages").attr("data-href")
		}, function()
		{
		});
		$("#goods_list_pages").on("click", "button[data-url]", function()
		{
			$("#admin_div").load(encodeURI($(this).attr("data-url")), {}, function()
			{
			});
		});

		$("#search_order_button").click(function()
		{
			var keyword = $("#keyword_of_order_input").val();
			if (keyword.length <= 0)
			{
				return false;
			}
			$("#admin_div").load(encodeURI("shop/show_return_order_list?s=${param.s}&k=" + keyword), {}, function()
			{
			});
		});
		$("#keyword_of_order_input").keydown(function(event)
		{
			if (event.keyCode == 13)
			{
				$("#search_order_button").trigger("click");
			}
		});
	});
</script>